﻿using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace CProd
{
    public partial class frmEntrada : Form
    {
        public static SqlConnection Conn = new SqlConnection(Properties.Settings.Default.conStr);

        public frmEntrada()
        {
            InitializeComponent();
        }

        private void btnUsers_Click(object sender, EventArgs e)
        {
            frmUtilizadores Users = (frmUtilizadores)Application.OpenForms["frmUtilizadores"];
            if (Users != null)
            {
                Users.WindowState = FormWindowState.Normal;
                Users.BringToFront();
                Users.Activate();
            }
            else
            {
                Users = new frmUtilizadores();
                Users.MdiParent = this;
                Users.Show();
            }
        }

        private void sairToolStripMenuItem_Click(object sender, EventArgs e)
        { this.Close(); }

        private void btnTarefas_Click(object sender, EventArgs e)
        {
            frmTarefas Tarefas = (frmTarefas)Application.OpenForms["frmTarefas"];
            if (Tarefas != null)
            {
                Tarefas.WindowState = FormWindowState.Normal;
                Tarefas.BringToFront();
                Tarefas.Activate();
            }
            else
            {
                Tarefas = new frmTarefas();
                Tarefas.MdiParent = this;
                Tarefas.Show();
            }
        }

        private void linhasToolClick(object sender, EventArgs e)
        {
            frmLinhas Linhas = (frmLinhas)Application.OpenForms["frmLinhas"];
            if (Linhas != null)
            {
                Linhas.WindowState = FormWindowState.Normal;
                Linhas.BringToFront();
                Linhas.Activate();
            }
            else
            {
                Linhas = new frmLinhas();
                Linhas.MdiParent = this;
                Linhas.Show();
            }
        }

        private void frmEntrada_Load(object sender, EventArgs e)
        {
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            this.MinimumSize = this.Size;
            this.Location = new System.Drawing.Point(0, 0);

            try
            {
                Conn.Open();
                Conn.Close();
            }
            catch
            {
                frmSql Sql = new frmSql();
                Sql.ShowDialog();
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        { Close(); }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            frmSaveLinhas_Tarefas Grava = (frmSaveLinhas_Tarefas)Application.OpenForms["frmSaveLinhas_Tarefas"];
            if (Grava != null)
            {
                Grava.WindowState = FormWindowState.Normal;
                Grava.BringToFront();
                Grava.Activate();
            }
            else
            {
                Grava = new frmSaveLinhas_Tarefas();
                Grava.MdiParent = this;
                Grava.Show();
            }
        }

        private void frmEntrada_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("Deseja mesmo sair?", "Confirme saída", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                e.Cancel = true;
        }

    }
}
